<?php
// +-------------------------------------------------------------------------+
// | PHP Version 5                                                           |
// +-------------------------------------------------------------------------+
// | ImaEngine - web development framework                                   |
// | Copyright (c) 2006-2007 Sardar Yumatov <ja.doma@gmail.com>              |
// +-------------------------------------------------------------------------+
// | This library is free software; you can redistribute it and/or modify it |
// | under the terms of the GNU Lesser General Public License as published   |
// | by the Free Software Foundation; either version 2.1 of the License, or  |
// | (at your option) any later version.                                     |
// |                                                                         |
// | This library is distributed in the hope that it will be useful, but     |
// | WITHOUT ANY WARRANTY; without even the implied warranty of              |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                    |
// | See the GNU Lesser General Public License for more details.             |
// |                                                                         |
// | You should have received a copy of the GNU Lesser General Public        |
// | License along with this library; if not, write to the Free Software     |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
// +-------------------------------------------------------------------------+

/**
* File contains generic to all packages exceptions.
*
* The exception set defined here describes most common things without specifying to much details.
* For example <tt>NotFoundException</tt> can be used to indicate that a file doesn't exist or a
* table in DB doesn't contain the record or queried user doesn't exists.
*
* Exceptions listed here indicating usually something critical (runtime) or signal a bug (logic).
*
* <b>Note:</b> this file may contain exceptions from SPL if they are not defined on the host platform.
*
* @package common
* @category Exceptions
* @author Sardar Yumatov <ja.doma@gmail.com>
* @copyright Copyright &copy; 2006-2007 Sardar Yumatov
*
* @PHP5only
*/

if(!defined('PROCESS')) {
	header('HTTP/1.1 404 Not Found');
	die('NotFound');
}

//class LogicException extends Exception {}
//class RuntimeException extends Exception {}

/**
 * Something is not supported or is  not implmented at all.
 * @author Sardar Yumatov <ja.doma@gmail.com>
 */
class UnsupportedException extends LogicException {}
/**
* When an operation is not supported.
*
* This exception may be thrown when an public interface must be implemented, but
* not all operations of that interface are applicable.
* @author Sardar Yumatov <ja.doma@gmail.com>
*/
class UnsupportedOperationException extends UnsupportedException {}

/** Thrown when an object expects API calling following some protocol/call sequence, but wrong order is detected */
class InvalidStateException extends LogicException {}

/**
* The requested object doesn't exist or is not defined.
* This is the base class for all runtime not-found exceptions.
* @author Sardar Yumatov <ja.doma@gmail.com>
*/
class NotFoundException extends RuntimeException {}

/**
* Something must be parsed and that something is of wrong syntax.
* This is mostly applicable on differend kind of input files. If you just
* expect an string-argument in specific format, then throw <tt>InvalidArgumentException</tt> instead.
* @author Sardar Yumatov <ja.doma@gmail.com>
*/
class SyntaxException extends RuntimeException {

        /** The string that has caused the problem.
        * @var string
        */
        protected $problem_string;

        /**
        * Construct syntax exception with optional string data to show the problem.
        * @param string $message the error message
        * @param string $string the string caused problem
        * @param integer $code the error code
        */
        public function __construct($message=null, $string=null, $code=0) {
                parent::__construct($message, $code);
                $this->problem_string = $string;
        }

        /**
        * Returns the string that has caused the problem'.
        * @return string null if not set, otherwise the string
        */
        public function getString() {
                return $this->problem_string;
        }
}

/**
* Required directory or file doesn't exists.
* This exception usually can't be thrown, but if it happens, then it means moving the installation base
* to another host was made badly and not all required resources are available now.
* @author Sardar Yumatov <ja.doma@gmail.com>
*/
class InstallationException extends Exception {}

/**
* The resource is unavailable, this is critial error.
* This exception will be thrown if, for example, a database connection can't be made.
* In most cases this exception should bubble up to root, where global try{} will catch these and serve a critical-error page.
* This is the base class for all unavaliable like exceptions.
* @author Sardar Yumatov <ja.doma@gmail.com>
*/
class UnavailableException extends RuntimeException {}


/**
 * Something is not resolved or understood
 * Will be thrown if something must to be resolved against something else and the
 * operation fails because of well known problem (not because of some PHP error).
 * This about resolving links in configuration files or resolving relative paths to absolute paths.
 * @author Sardar Yumatov <ja.doma@gmail.com>
 */
class UnresolvedException extends RuntimeException {}

/**
 * If a relative path tries to point higher than given base directory (security).
 * Many modules when including some files from a base path want ensure the path never goes
 * higher than base for security reasons. This exception indicates a hacker attack or
 * bug in your code.
 * @author Sardar Yumatov <ja.doma@gmail.com>
 */
class BasePathException extends UnresolvedException {}

/**
* Thrown if some of file or stream operations fail.
* @author Sardar Yumatov <ja.doma@gmail.com>
*/
class IOException extends RuntimeException {}
?>